<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PhoneticToEnglishForTengwarTranscriberTest</title>

<link rel="stylesheet"
	href="http://code.jquery.com/qunit/qunit-1.15.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>

<script src="../../main/js/util/Logger.js"></script>

<script src="../../main/js/PhoneticToEnglishForTengwarTranscriber.js"></script>
<script src="../../main/js/TengwaRune.js"></script>

<script src="../../main/js/example/TengwarExampleTLOTR2.js"></script>

<script src="../../main/js/example/TengwarExampleTS1.js"></script>
<script src="../../main/js/example/TengwarExampleTS2.js"></script>

<script src="../../main/js/example/TengwarExampleUTONAME1.js"></script>
<script src="../../main/js/example/TengwarExampleUTONAME2.js"></script>

<script src="../../main/js/example/TengwarExampleTROTS1.js"></script>
<script src="../../main/js/example/TengwarExampleTROTS2.js"></script>

<script src="../../main/js/example/TengwarExampleTTOI1.js"></script>
<script src="../../main/js/example/TengwarExampleTTOI2.js"></script>

<script src="../../main/js/example/TengwarExampleTWOTR1.js"></script>
<script src="../../main/js/example/TengwarExampleTWOTR2.js"></script>

<script src="../../main/js/example/TengwarExampleSD1.js"></script>
<script src="../../main/js/example/TengwarExampleSD2.js"></script>

<script>
    var LOGGER = new Logger();

    /**************************************************************************
     * languageWordsToString()
     */

    QUnit.test("Example TLOTR2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTLOTR2.LANGUAGE_WORDS,
                TengwarExampleTLOTR2.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TS1 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTS1.LANGUAGE_WORDS,
                TengwarExampleTS1.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TS2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTS2.LANGUAGE_WORDS,
                TengwarExampleTS2.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example UTONAME1 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert,
                TengwarExampleUTONAME1.LANGUAGE_WORDS,
                TengwarExampleUTONAME1.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example UTONAME2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert,
                TengwarExampleUTONAME2.LANGUAGE_WORDS,
                TengwarExampleUTONAME2.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TROTS1 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTROTS1.LANGUAGE_WORDS,
                TengwarExampleTROTS1.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TROTS2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTROTS2.LANGUAGE_WORDS,
                TengwarExampleTROTS2.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TTOI1 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTTOI1.LANGUAGE_WORDS,
                TengwarExampleTTOI1.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TTOI2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTTOI2.LANGUAGE_WORDS,
                TengwarExampleTTOI2.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TWOTR1 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTWOTR1.LANGUAGE_WORDS,
                TengwarExampleTWOTR1.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example TWOTR2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleTWOTR2.LANGUAGE_WORDS,
                TengwarExampleTWOTR2.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example SD1 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleSD1.LANGUAGE_WORDS,
                TengwarExampleSD1.LANGUAGE_STRING.toLowerCase());
    });

    QUnit.test("Example SD2 languageWordsToString()", function(assert)
    {
        testLanguageWordsToString(assert, TengwarExampleSD2.LANGUAGE_WORDS,
                TengwarExampleSD2.LANGUAGE_STRING.toLowerCase());
    });

    /**************************************************************************
     * phonemesToLanguageWords()
     */

    QUnit.test("Example TLOTR2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTLOTR2.PHONEMES,
                TengwarExampleTLOTR2.LANGUAGE_WORDS);
    });

    QUnit.test("Example TS1 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTS1.PHONEMES,
                TengwarExampleTS1.LANGUAGE_WORDS);
    });

    QUnit.test("Example TS2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTS2.PHONEMES,
                TengwarExampleTS2.LANGUAGE_WORDS);
    });

    QUnit.test("Example UTONAME1 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleUTONAME1.PHONEMES,
                TengwarExampleUTONAME1.LANGUAGE_WORDS);
    });

    QUnit.test("Example UTONAME2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleUTONAME2.PHONEMES,
                TengwarExampleUTONAME2.LANGUAGE_WORDS);
    });

    QUnit.test("Example TROTS1 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTROTS1.PHONEMES,
                TengwarExampleTROTS1.LANGUAGE_WORDS);
    });

    QUnit.test("Example TROTS2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTROTS2.PHONEMES,
                TengwarExampleTROTS2.LANGUAGE_WORDS);
    });

    QUnit.test("Example TTOI1 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTTOI1.PHONEMES,
                TengwarExampleTTOI1.LANGUAGE_WORDS);
    });

    QUnit.test("Example TTOI2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTTOI2.PHONEMES,
                TengwarExampleTTOI2.LANGUAGE_WORDS);
    });

    QUnit.test("Example TWOTR1 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTWOTR1.PHONEMES,
                TengwarExampleTWOTR1.LANGUAGE_WORDS);
    });

    QUnit.test("Example TWOTR2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleTWOTR2.PHONEMES,
                TengwarExampleTWOTR2.LANGUAGE_WORDS);
    });

    QUnit.test("Example SD1 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleSD1.PHONEMES,
                TengwarExampleSD1.LANGUAGE_WORDS);
    });

    QUnit.test("Example SD2 phonemesToLanguageWords()", function(assert)
    {
        testPhonemesToLanguageWords(assert, TengwarExampleSD2.PHONEMES,
                TengwarExampleSD2.LANGUAGE_WORDS);
    });

    /**************************************************************************
     * Utility functions.
     */

    function createTranscriber()
    {
        return new PhoneticToEnglishForTengwarTranscriber();
    }

    function testLanguageWordsToString(assert, words, expected)
    {
        // Setup.
        var transcriber = createTranscriber();

        // Run.
        var result = transcriber.languageWordsToString(words);

        // Verify.
        assert.ok(result);
        assert.equal(result.length, expected.length);
        assert.equal(result, expected);
    }

    function testPhonemesToLanguageWords(assert, phonemes, expected,
            useComparison)
    {
        // Setup.
        var transcriber = createTranscriber();

        // Run.
        var result = transcriber.phonemesToLanguageWords(phonemes);

        // Verify.
        verify(assert, result, expected, useComparison);
    }

    function verify(assert, result, expected, useComparison)
    {
        assert.ok(result);
        assert.equal(result.length, expected.length);

        if (useComparison)
        {
            assert.equal(result, expected);
        }

        for (var i = 0; i < expected.length; i++)
        {
            if (Array.isArray(expected[i]))
            {
                verify(assert, result[i], expected[i], useComparison);
            }
            else
            {
                assert.equal(result[i], expected[i]);
            }
        }
    }
</script>
</head>
<body>
	<div id="qunit"></div>
</body>
</html>
